window.onload = function () {
    var xhr = new XMLHttpRequest()
    xhr.open('get', '/studio/album/list.json')
    xhr.onload = function () {
        var data = JSON.parse(xhr.responseText)
        var currentUser = data.currentUser;
        if (currentUser === null) {
            alert("用户未登陆")
        } else {
            var oTable = document.querySelector('table')
            var list = data.albumList
            for (var i in list) {
                var tmp = list[i]
                var anchor
                if (tmp.state === '已发布') {
                    anchor = `<a href="/studio/album/withdraw.do?aid=${tmp.aid}">下线</a>`
                } else {
                    anchor = `<a href="/studio/album/publish.do?aid=${tmp.aid}">发布</a>`
                }
                var html = `<tr><td>${tmp.aid}</td><td>${tmp.title}</td><td><img src="${tmp.cover}"></td><td>${tmp.state}</td><td><a href="/studio/album/bind.html?aid=${tmp.aid}">音频</a></td><td>${anchor}</td></tr>`
                oTable.innerHTML += html
            }
        }
    }
    xhr.send()
}